#pragma once

#include "GfxObject.h"

namespace mmath
{
	struct FrustumPersp;
}

namespace mgfx
{
	class DirectionalLight : public GfxObject
	{
	public:
		DirectionalLight()
		{
			Color = XMCOLOR3F(1.0f, 1.0f, 1.0f);
			Intensity = 0.9f;
			//Direction = XMFLOAT3(-40.0f, 50.0f, -100.0f);
			Direction = XMFLOAT3(0.0f, -1.0f, 0.0f);
		}
		XMCOLOR3F Color;
		float Intensity;
		XMFLOAT3 Direction;
	};

	struct PointLightDesc
	{
		PointLightDesc();
		XMCOLOR3F Color;
		float Intensity;
		float Radius;
		float Falloff;
	};

	class PointLight : public GfxObject
	{
	public:
		XMCOLOR3F Color;
		float Intensity;
		float Radius;
		float Falloff;

		void init(const PointLightDesc & desc);

		virtual PointLight* copy() const;
	};

	struct SpotLightDesc
	{
		SpotLightDesc();
		XMCOLOR3F Color;
		float Intensity;
		float Radius;
		float Falloff;
		float SpotAngleRad;
		float SpotFalloff;
		bool IsCastingShadows;
	};

	class SpotLight : public GfxObject
	{
	public:
		void init(const SpotLightDesc & desc);
		void initShadowMap();

		void updateDerivedValues();

		// calculates bounding frustum of light's influence area and writes out to frustum arg
		void getViewFrustum(mmath::FrustumPersp & frustum);

		static XMVECTOR InitialDirection;

		float Radius;
		XMCOLOR3F Color;
		float Intensity;
		float Falloff;

		float SpotAngleRad;
		float SpotFalloff;

		int ShadowMap;
		bool IsCastingShadows;
		uint ShadowMapWidth;
		uint ShadowMapHeight;

		// derived values
		XMFLOAT4X4 ProjectionMatrix;
		float SpotCosAngle;

		virtual SpotLight* copy() const;
	};
}